#include<iostream>
#include"EquationSolver.h"

double epsi=std::numeric_limits<double>::epsilon();

class myf_1 : public Function
  {
  public:
    double operator()(double x){
      double B = 11.5/180.0*acos(-1);
	return 89*sin(B)*sin(x)*cos(x)+89*cos(B)*sin(x)*sin(x)-((49+27.5)*sin(B)-27.5*tan(B))*cos(x)-((49+27.5)*cos(B)-27.5)*sin(x);
    }
    double diff(double x){
    double f;
    f = (this->operator()(x)-this->operator()(x-1e-8))/1e-8;
    return f;
  }
  };
  class myf_2 : public Function
  {
  public:
    double operator()(double x){
      double B = 11.5/180.0*acos(-1);
	return 89*sin(B)*sin(x)*cos(x)+89*cos(B)*sin(x)*sin(x)-((49+15)*sin(B)-15*tan(B))*cos(x)-((49+15)*cos(B)-15)*sin(x);
    }
    double diff(double x){
    double f;
    f = (this->operator()(x)-this->operator()(x-1e-8))/1e-8;
    return f;
  }
  };
int main(void){
  myf_1 f_1;
  myf_2 f_2;
  Newton<myf_1> New_1(33/180.0*acos(-1), 20, f_1);
  Newton<myf_2> New_2(33/180.0*acos(-1), 20, f_2);
  Secant<myf_1> Sec_1(1.4, 1.5, 20, epsi, f_1);
  double *R_1 = New_1.solve();
  double *R_2 = New_2.solve();
  double *R_3 = Sec_1.solve();
  std::cout<<"a小题的结果为："<<std::endl;
  std::cout<<"根为"<<R_1[0]/acos(-1)*180<<"度"<<std::endl;
  std::cout<<"迭代次数为"<<R_1[1]<<std::endl;
  std::cout<<"误差为"<<f_1(R_1[0])<<std::endl;
  std::cout<<"*******************************************************"<<std::endl;    
  std::cout<<"b小题的结果为："<<std::endl;
  std::cout<<"根为"<<R_2[0]/acos(-1)*180<<"度"<<std::endl;
  std::cout<<"迭代次数为"<<R_2[1]<<std::endl; 
  std::cout<<"误差为"<<f_2(R_2[0])<<std::endl;
  std::cout<<"*******************************************************"<<std::endl;    
  std::cout<<"c小题的结果为："<<std::endl;
  std::cout<<"根为"<<R_3[0]/acos(-1)*180<<"度"<<std::endl;
  std::cout<<"迭代次数为"<<R_3[1]<<std::endl;
  std::cout<<"误差为"<<f_1(R_3[0])<<std::endl;
  return 0;
};
 